package com.tfd.blog.domain;

import com.tfd.blog.utlis.BlogConstants;
import com.tfd.blog.utlis.DateUtils;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * 文章实体
 *
 * @author TangFD@HF 2019/5/8
 */
@Data
@Entity
@Table(name = "t_blog_article")
public class Article {

    @Id
    @Column(length = 32)
    @GenericGenerator(name = "idGenerator", strategy = "uuid")
    @GeneratedValue(generator = "idGenerator")
    private String id;

    @Column(nullable = false, length = 100)
    private String title;

    @Column(nullable = false, length = 200)
    private String description;

    @Column(nullable = false, length = 32)
    private String categoryId;

    @Column(nullable = false, length = 20)
    private String status = BlogConstants.BLOG_STATUS_DRAFT;

    private String content;

    @Column(length = 32)
    private String coverId;

    @Column(length = 1)
    private boolean recommend;

    private int readCount = 0;
    private int likeCount = 0;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createDate;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date publishDate;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateDate;

    @Transient
    private List<String> labels;
    @Transient
    private String dateStr;
    @Transient
    private String categoryName;
    @Transient
    private Article pre;
    @Transient
    private Article next;

    public String getDateStr() {
        return DateUtils.timeFormat(this.publishDate);
    }
}
